/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package asa;

import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Mickael
 */
public class ASAExprIdent extends ASAExpr implements NeedBlocInterface{

    private String nomVar;
    private List<ASAExpr> indices = null;
    private boolean isArray = false;
    private ASABloc bl = null;

    public ASAExprIdent(String nomVar, List<ASAExpr> indices) {
        if (indices.isEmpty()) {
            this.nomVar = nomVar;
            indices = null;
        } else {
            isArray = true;
            this.nomVar = nomVar;
            this.indices = indices;
        }
                
    }

    public void setBl(ASABloc bl) {
        this.bl = bl;
        if (isArray) {
            for (ASAExpr expr : indices) {
                expr.setBl(bl);
            }
        }
    }
    
    
   
    public List<ASAExpr> getIndex() {
        return indices;
    }

    public String getNomVar() {
        return nomVar;
    }

    
    
    
    
    @Override
    public String getLabelExplorateur() {
        return "ID " + nomVar;
    }
    
    @Override
    public int evalue() {
        int valeur = 0;
        Variables v = Variables.getInstance();
        if (isArray) {
            List<Integer> index = new ArrayList<Integer>();
            for(ASAExpr expr : indices) {
                index.add(expr.evalue());
            }
            valeur = v.getValue(bl, nomVar, index);
        } else {
            /*
            Integer i = v.getValue(bl,nomVar);
            Integer g = v.getValue(null, nomVar);
            if(g != null)
                i=g;
            if (i == null) {
                valeur = 0;
            } else {
                valeur = i;
            }*/
            Integer i = v.getValue(bl,nomVar);
            valeur = i;
        }
        return valeur;
    }

}
